<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${title} + ' - 图书管理系统'"></title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
</head>
<body>
<nav th:replace="fragments/navbar :: navbar"></nav>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-8 offset-md-2">
            <div class="card">
                <div class="card-header">
                    <h3 th:text="${title}"></h3>
                </div>
                <div class="card-body">
                    <!-- 错误提示 -->
                    <div th:if="${error}" class="alert alert-danger mb-4">
                        <span th:text="${error}"></span>
                    </div>

                    <!-- 表单提交路径：新增提交到/readers，编辑提交到/readers/update/{id} -->
                    <form th:action="@{${reader.id != null ? '/readers/update/' + reader.id : '/readers'}}" method="post">
                        <!-- 姓名（必填，实体类中name非空） -->
                        <div class="form-group">
                            <label for="name">姓名 <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" id="name" name="name"
                                   th:value="${reader.name}" required>
                        </div>

                        <!-- 电话 -->
                        <div class="form-group">
                            <label for="phone">电话</label>
                            <input type="text" class="form-control" id="phone" name="phone"
                                   th:value="${reader.phone}">
                        </div>

                        <!-- 邮箱 -->
                        <div class="form-group">
                            <label for="email">邮箱</label>
                            <input type="email" class="form-control" id="email" name="email"
                                   th:value="${reader.email}">
                        </div>

                        <!-- 地址 -->
                        <div class="form-group">
                            <label for="address">地址</label>
                            <textarea class="form-control" id="address" name="address" rows="2"
                                      th:text="${reader.address}"></textarea>
                        </div>

                        <!-- 启用状态 -->
                        <div class="form-check">
                            <input type="checkbox" class="form-check-input" id="active" name="active"
                                   th:checked="${reader.active != null ? reader.active : true}">
                            <label class="form-check-label" for="active">启用该读者</label>
                        </div>

                        <!-- 提交按钮 -->
                        <div class="text-right mt-4">
                            <a href="/readers" class="btn btn-secondary mr-2">取消</a>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>